<%@ page import="Dao.MainTypeDao" %>
<%@ page import="Service.MainTypeService" %>
<%@ page import="Service.Impl.MainTypeServiceImpl" %>
<%@ page import="Domain.MainType" %>
<%@ page import="java.util.List" %>
<%@ page import="Domain.Product" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="Service.NoticeService" %>
<%@ page import="Service.Impl.NoticeServiceImpl" %>
<%@ page import="Domain.Notice" %>
<%@ page import="Dao.Impl.ProductDapImpl" %>
<%@ page import="Service.ProductService" %>
<%@ page import="Service.Impl.ProductServiceImpl" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>


<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="./static/css/main.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
    <title>商城</title>
</head>

<body>

<c:if test="${empty user}">
    <div class="top-nav">
        <div class="container clearf">
            <div class="left">
                <a href="${pageContext.request.contextPath}/Index.jsp" class="item">首页</a>
            </div>

            <div class="right">
                <a href="${pageContext.request.contextPath}/Register.jsp" class="item">注册/登录</a>
            </div>
        </div>
    </div>
</c:if>

<c:if test="${not empty user}">
    <div class="top-nav">
        <div class="container clearf">
            <div class="left">
                <a href="${pageContext.request.contextPath}/UserServlet?action=BackToIndex&id=${user.id}" class="item">首页</a>
            </div>

            <div class="right">
                <div class="dropdown item">
                    <a class="item">欢迎您，${user.username}</a>
                    <div class="dropdown-content">
                        <a href="${pageContext.request.contextPath}/UserServlet?action=UserInf&id=${user.id}">个人信息</a>
                        <a href="${pageContext.request.contextPath}/OrdersServlet?action=Orderselect&uid=${user.id}">我的订单</a>
                        <a href="${pageContext.request.contextPath}/CartServlet?action=IntoCart&id=${user.id}">我的购物车</a>
                        <a href="${pageContext.request.contextPath}/CollectionServlet?action=IntoCollection&id=${user.id}">我的收藏夹</a>
                        <a href="${pageContext.request.contextPath}/UserServlet?action=LogOut">退出登录</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</c:if>

<%
    MainTypeService service = new MainTypeServiceImpl();
    List<MainType> list1 = service.FindALLMainType();
    request.setAttribute("map", list1);

    NoticeService service1 = new NoticeServiceImpl();
    List<Notice> list = service1.FindAllNotice();
    request.setAttribute("notice", list);

    ProductService service3 = new ProductServiceImpl();
    List<Product> products = service3.FindProductAll();
    request.setAttribute("pall", products);

%>

<div class="header">
    <div class="container clearf">
        <div class="col-1 logo">商城</div>

        <c:forEach items="${map}" var="m" varStatus="i">
            <div class="dropdown">
                <a class="dropbtn"
                   href="${pageContext.request.contextPath}/ProductServlet?action=findMainTypeById&pid=${m.id}&uid=${user.id}">${m.pname}</a>
            </div>
        </c:forEach>
        <form action="${pageContext.request.contextPath}/ProductServlet?action=search&uid=${user.id}" method="post">
            <div class="col-5 search-bar">
                <input type="text" name="main_name">
                <button type="submit">搜索</button>
            </div>
        </form>
    </div>
</div>
</br>
<div class="main-promote">
    <div class="container clearf">
        <div class="col-7" style="">
            <div class="layui-carousel" id="test10">
                <div carousel-item="">
                    <div><img src="${pageContext.request.contextPath}/img/9.png"></div>
                    <div><img src="${pageContext.request.contextPath}/img/9R.png"></div>
                    <div><img src="${pageContext.request.contextPath}/img/201515-158211451517f1.jpg"></div>
                    <div><img src="${pageContext.request.contextPath}/img/9R.png"></div>
                    <div><img src="${pageContext.request.contextPath}/img/9.png"></div>
                    <div><img src="${pageContext.request.contextPath}/img/201515-158211451517f1.jpg"></div>
                    <div><img src="${pageContext.request.contextPath}/img/9.png"></div>
                </div>
            </div>
        </div>

        <div class="col-2 info">
            <div class="anno">
                <div class="title">公告</div>
            </div>
            <div class="auth clearf">
                <div class="">你好，欢迎剁手.</div>
                <marquee behavior="alternate" direction="down" onmouseover="this.stop();" onmouseout="this.start();">
                    <c:forEach items="${notice}" var="n" varStatus="i">
                        <a href="${pageContext.request.contextPath}/NoticeServlet?action=IntoNotice&uid=${user.id}&nid=${n.id}">
                            <p>【公告】${n.title}</p></a>
                    </c:forEach>
                </marquee>
            </div>
        </div>

    </div>
</div>
</br>
</br>
<div class="container clearf">
    <div class="cat-promote">
        <div class="title">4G</div>
        <div class="content">
            <c:forEach items="${pall}" var="n" varStatus="c">
                <div class="col-2 item">
                    <div class="card" style="text-align: center">
                        <a href="${pageContext.request.contextPath}/ProductServlet?action=IntoProduct&pid=${n.id}&uid=${user.id}">
                            <img src="./img/${n.picture}" alt="" style="height: 200px">
                            <a>${n.name}</a>
                            <h2 style="color: red">￥${n.price}</h2>
                        </a>
                    </div>
                </div>
            </c:forEach>
        </div>
    </div>
</div>


</br>
</br>

</br>
</br>

<div class="footer">
    <div class="container clearf">
        <div class="">© 2021 版权所有 粤ICP备11111111号 |隐私政策|用户使用协议|资质证照|知识产权</div>
    </div>
</div>


<script>
    layui.use(['carousel', 'form'], function(){
        var carousel = layui.carousel
            ,form = layui.form;

        //常规轮播
        carousel.render({
            elem: '#test1'
            ,arrow: 'always'
        });

        //改变下时间间隔、动画类型、高度
        carousel.render({
            elem: '#test2'
            ,interval: 1800
            ,anim: 'fade'
            ,height: '120px'
        });

        //设定各种参数
        var ins3 = carousel.render({
            elem: '#test3'
        });
        //图片轮播
        carousel.render({
            elem: '#test10'
            ,width: '778px'
            ,height: '300px'
            ,interval: 5000
        });

        //事件
        carousel.on('change(test4)', function(res){
            console.log(res)
        });

        var $ = layui.$, active = {
            set: function(othis){
                var THIS = 'layui-bg-normal'
                    ,key = othis.data('key')
                    ,options = {};

                othis.css('background-color', '#5FB878').siblings().removeAttr('style');
                options[key] = othis.data('value');
                ins3.reload(options);
            }
        };

        //监听开关
        form.on('switch(autoplay)', function(){
            ins3.reload({
                autoplay: this.checked
            });
        });

        $('.demoSet').on('keyup', function(){
            var value = this.value
                ,options = {};
            if(!/^\d+$/.test(value)) return;

            options[this.name] = value;
            ins3.reload(options);
        });

        //其它示例
        $('.demoTest .layui-btn').on('click', function(){
            var othis = $(this), type = othis.data('type');
            active[type] ? active[type].call(this, othis) : '';
        });
    });
</script>
</body>
</html>
